home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 319.adf / CNewsSrc / cnews.src.lzh / libcnews / time.c < prev   
C/C++ Source or Header  |  1989-07-13  |  914b  |  42 lines

  1. /*
  2.  * time utilities
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #ifndef AMIGA
  8. # include <sys/timeb.h>        /* Amiga's is in libc.h */
  9. #endif /* !AMIGA */
  10. #include "libc.h"
  11. #include "news.h"
  12.  
  13. /*
  14.  * Write a timestamp of the form "Jun 12 12:34:56.789" on fp.
  15.  * N.B.: no trailing newline is written.
  16.  */
  17.  
  18. void timestamp(fp, timep)
  19. FILE *fp;
  20. time_t *timep;    /* if non-null, return time() here for later use */
  21. {
  22. #ifdef AMIGA
  23.     time_t time_now;
  24.  
  25.     (void) time(&time_now);
  26.     (void) fprintf(fp, "%.15s.000", ctime(&time_now) + 4);
  27.     if (timep != NULL)
  28.         *timep = time_now;
  29. #else
  30.     struct timeb ftnow;
  31.     char ms[4];                /* room for "123" and a NUL */
  32.  
  33.     ftime(&ftnow);
  34.     if (timep != NULL)
  35.         *timep = ftnow.time;
  36.     /* .15 excludes yyyy\n\0; + 4 omits day-of-week */
  37.     (void) fprintf(fp, "%.15s.", ctime(&ftnow.time) + 4);
  38.     (void) ltoza(ms, (long)ftnow.millitm, 3);    /* 3 digits of output */
  39.     (void) fputs(ms, fp);
  40. #endif /* AMIGA */
  41. }
  42.